<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
</html>
<script>
    /**
     * 对locastorage的封闭 兼容ie9+
     * @param sessionNameArr [Array] 需要管理的对locastorage键名数据  eg:['a','b','c',...]
     *
     * 操作locastorage方式 eg:
     * startSession(['keyname']);
     * SESSION.keyname=true;//赋值
     * var a=SESSION.keyname;//获取  a=true
     *
     */
    function startSession(sessionNameArr) {
        var attrs = [], tmpsession = {},str="",v=sessionNameArr;
        if (Object.prototype.toString.call(v) == "[object Array]") {
            for (var k = 0; k < v.length; k++) {
                attrs.push(v[k]);
                if (localStorage.getItem(v[k])) {
                    //载入已有locaStorage数据
                    tmpsession[v[k]]=localStorage.getItem(v[k]);
                }
            }
        }
        for (var i = 0; i < attrs.length; i++) {
            str += "_" + attrs[i] + ':null,get ' + attrs[i] + '(){return this._' + attrs[i] + ';},set ' + attrs[i] + '(v){this._' + attrs[i] + '=v;localStorage.setItem("' + attrs[i] + '",v);},';
        }
        str = "window.SESSION={" + str.substr(0, str.length - 1) + "};";
        new Function(str)();
        for (i in tmpsession){
            window.SESSION[i] = tmpsession[i];
        }
    }

    /*eg:
    startSession(['a', 'b', 'c', 'd', 'e']);//初始化页面
    SESSION.c={rr:55};
    console.log(SESSION);
    */


</script>